package io.github.wanggit.antrpc.commons.bean;

import io.github.wanggit.antrpc.commons.utils.JsonUtils;

import java.util.Map;

public abstract class InterfaceNodeDataBeanHelper {

    /**
     * 默认节点数据中包含的是服务提供端限流信息，所以服务消费端不保存此限流信息
     *
     * @return node data
     */
    public static InterfaceNodeDataBean getNodeDataWithoutRateLimiting(byte[] bytes) {
        InterfaceNodeDataBean interfaceNodeDataBean =
                JsonUtils.fromJson(bytes, InterfaceNodeDataBean.class);
        Map<String, RegisterBeanMethod> methodMap = interfaceNodeDataBean.getMethodMap();
        if (null != methodMap) {
            methodMap.forEach(
                    (key, value) -> {
                        // 清除来自于服务提供端的限流信息
                        value.setLimit(0);
                        value.setDurationInSeconds(0);
                    });
        }
        return interfaceNodeDataBean;
    }
}
